(function ($) {

         // 点击修改按钮,显示需要
        $(".showUpdateRoom").on('click',function () {


            var rid = $(this).val()
            console.log(rid)
            $.ajax({
                url: "/hms/room/"+rid,
                method:"GET",
                dataType:'JSON',
                success(data){
                    console.log(data)
                    $("#updateRoomForm input[name='rid']").val(data.data[0].rid)
                    $("#updateRoomForm input[name='roomtype']").val(data.data[0].roomtype)
                    $("#updateRoomForm select[name='food']").val(data.data[0].food)
                    $("#updateRoomForm select[name='status']").val(data.data[0].status)
                    $("#updateRoomForm input[name='capacity']").val(data.data[0].capacity)
                    $("#updateRoomForm input[name='price']").val(data.data[0].price)
                    $("#updateRoomForm input[name='size']").val(data.data[0].size)
                },
                error(){
                    alert("请授权之后再来哦" )

                }
            })

        })



    //点击关闭模态框清除数据
    $("#closeModal").on('click', function () {
        $("#updateform")[0].reset()
    })

    //提交修改请求
    $("#update").on('click',function () {
        var updateRoom = $("#updateRoomForm").serialize()
        console.log(updateRoom)
        $.ajax({
            url:"/hms/room",
            method: "PUT",
            data:updateRoom,
            dataType: 'JSON',
            success(data){

                alert(data.msg)
                window.location.href = "rooms"
            }

        })
    })


    //删除按钮的点击事件，利用删除表单来做，拿到删除按钮的路径
    $(".deleteRoomBtn").on('click',function () {
        $("#deleteForm").attr("action",$(this).attr("del_uri")).submit();
        return false

    })




})(jQuery)
